package com.example.devtool.db.consts;

import com.example.devtool.db.exception.DbException;
import lombok.Getter;

/**
 * @author zhuliangxuan
 * @date
 * 数据库类型枚举
 */
@Getter
public enum DbTypeEnum {
    MYSQL5("mysql", 1, "com.mysql.jdbc.Driver", "","mysql5 db"),
    MYSQL8("mysql", 2, "com.mysql.cj.jdbc.Driver", "","mysql8 db"),
    MARIADB("mariadb", 3, "org.mariadb.jdbc.Driver", "","mariadb"),
    ;

    final Integer code;
    final String type;
    final String drivePath;
    final String urlFormat;
    final String desc;

    DbTypeEnum(String type, Integer code, String drivePath, String urlFormat, String desc) {
        this.code = code;
        this.type = type;
        this.drivePath = drivePath;
        this.urlFormat = urlFormat;
        this.desc = desc;
    }

    public static DbTypeEnum getFromCode(Integer code) {
        for (DbTypeEnum dbTypeEnum : values()) {
            if (dbTypeEnum.getCode().equals(code)) {
                return dbTypeEnum;
            }
        }
        throw new DbException("没有对应的数据库类型");
    }
}
